<template>
  <s-layout
    title="我的"
    tabbar="/pages/index/user"
    navbar="custom"
    :bgStyle="template.style?.background"
    :navbarStyle="template.style?.navbar"
    
    :showFloatButton="true" 
  >
  
  
    <s-block v-for="(item, index) in template.data" :key="index" :styles="item.style">
      <s-block-item :type="item.type" :data="item.data" :styles="item.style" />
    </s-block>
  </s-layout>
</template>
<script>
	var QQMapWX = require("../../static/qqmap-wx-jssdk.min");
	var qqmapsdk;
</script>

<script setup>
  import { computed } from 'vue';
  import { onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
  import sheep from '@/sheep';

  // 隐藏原生tabBar
  uni.hideTabBar();
  // console.log(JSON.parse(uni.getStorageSync('user-store')))
  const template = computed(() => sheep.$store('app').template.user);
  const isLogin = computed(() => sheep.$store('user').isLogin);

  onShow(() => {
    sheep.$store('user').updateUserData();
	console.log(sheep.$store('user').userInfo.city)			
	if(sheep.$store('user').userInfo.city== "" || sheep.$store('user').userInfo.city==null)
	{
		 getLocalCity();
	}
  });

  onPullDownRefresh(() => {
    sheep.$store('user').updateUserData();
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 800);
  });

  onPageScroll(() => {});
  
  
  
  async function getLocalCity() {
	  	console.log("getLocalCity");
  				wx.getFuzzyLocation({
  					type: 'wgs84',
  					success(res) {
  					
  						qqmapsdk = new QQMapWX({
  								key: "EJQBZ-EFDRQ-P2C5J-GLP5J-WORHT-3ZBCN"
  							}),
  						this.latitude = res.latitude;
  						this.longitude = res.longitude;
  						qqmapsdk.reverseGeocoder({
  							location: {
  								latitude: this.latitude,
  								longitude: this.longitude
  							},
  							success: function(res) {
  								let city =res.result.address_component.city
								
								 sheep.$api.user.updateusercity({
								      city: city
								    });
  								console.log(city)
  							},
  							fail: function(err) {
  								console.log(err);
  							},
  						})
  					},
  				  fail(err) {
  					console.error(err);
  				  }
  				})
  			}
</script>

<style></style>
